package cn.edu.buaa.purain.rest;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;



@SuppressWarnings("rawtypes")
public class PurainHttpHeaderHelper {
	
	static Map<String, Integer> httpParaValues = null;
	
	
	public static Map<String, Integer> getHttpParaValues() throws HttpParameterNotInitializerException {
		if (null == httpParaValues) {
			throw new HttpParameterNotInitializerException("httpParaValues not initialized...");
		}
		return httpParaValues;
	}

	public static void init(PurainHttpHeader restHttpParameter) throws TooManyHttpHeaderFieldException {
		httpParaValues = new HashMap<String, Integer>();
	
		Class clazz = restHttpParameter.getClass();	
		Field[] fields = clazz.getDeclaredFields();
		
		if (fields.length > 31) {
			throw new TooManyHttpHeaderFieldException("fields' length > 31");
		}
		
		int base = 1;
		for (Field f : fields) {
			httpParaValues.put(f.getName(), base);
			base *= 2;
		}
	}
}
